<div id="street-list">

    <?php $this->addScriptPath('../application/views/scripts/'); ?>
    <?= $this->paginationControl($this->paginator, 'Sliding', 'paginator.phtml') ?>

    <div class="clr"></div>

    <table class="dataActions" width="100%" border="0" cellpadding="0" cellspacing="0" >

        <tr>
            <th>Switch</th>
            <th>Team members</th>
            <th>Assign Houses</th>
            <th>Houses</th>
            <th>Progress</th>
            <th>Files</th>
            <th>Status</th>            
        </tr>
        <?php
        foreach ($this->paginator as $item) {
            $progress = $this->installationProgress($item['id']);
            ?>

            <script>
                $(function() {
                    $( "#<?php echo $item['id']; ?>" ).progressbar({
                        value: <?php echo intval($progress); ?>
                    });
                });    
            </script>
            <tr>
                <?php
                $teamNames = $this->installTeamNames($item['id']);
                ?>
                <td><?php echo $item['name']; ?></div></td>
                <td><?php echo (!empty($teamNames) ? $teamNames : '<a href="javascript:void(0)" onClick="assignTeam(' . $item['id'] . ',' . $item['cabinet'] . ')">Assign Team</a>') ?></td>
                <td>
                    <?php
                    if (!empty($teamNames)) {
                        ?>
                        <a href="javascript:void(0)" onclick="assignHouses('<?php echo $item['id']; ?>')">Assign Houses</a>
                        <?php
                    } else {
                        echo '-';
                    }
                    ?>
                </td>
                <td><a href="<?php echo $this->url(array('module'=>'installation','controller' => 'house', 'action' => 'index', 'id' => $item['id'])); ?>">Houses</a></td>
                <td><div id="<?php echo $item['id']; ?>"></div></td>
                <td><a href="javascript:void(0)" onclick="addFiles('<?php echo $item['id']; ?>','<?php echo $item['cabinet']; ?>')"> files</a></td>
                <td><a href="javascript:void(0)" onclick="toggleStatus('<?php echo $item['id']; ?>','<?php echo $item['installation_status']; ?>','<?php echo $item['cabinet']; ?>')"><?php echo ($item['installation_status'] == 1) ? 'Open' : 'Close'; ?></a></td>

            </tr>           
<?php } ?>


    </table>
</div>
<script>
    function toggleStatus(id,status,cabinetId){
        $.ajax({
            type: "POST",
            url: "<?= $this->baseURI(); ?>installation/notification/toggle/"+id, 
            data:({status:status}),
            success: function(msg){
                $("#street-list").load("<?= $this->baseURI(); ?>installation/notification/list/"+cabinetId);
            }
        }); 
    }
    function updateList(id){        
        $("#street-list").load("<?= $this->baseURI(); ?>installation/notification/list/"+id);
           
    }
    
    
    
    function addFiles(id,cabinet) {
        $("#add-document-form").load("<?= $this->baseURI(); ?>installation/notification/files/"+id+"/"+cabinet);
        $( "#add-document-form" ).dialog( "open" );
    }
</script>